package com.hrserviceserve.controller;

import com.hrserviceserve.entity.Contract;
import com.hrserviceserve.entity.Result;
import com.hrserviceserve.service.ContractService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@Api(tags = "合同接口")
@RequestMapping("/contract")
public class ContractController {
    @Autowired
    ContractService contractService;

    @GetMapping
    public Result findAll(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit,
                          @RequestParam(value = "name",required = false) String name,
                          @RequestParam(value = "position",required = false) String position){
        Map<String,Object> map=new HashMap<>();
        map.put("page",page);
        map.put("limit",limit);
        map.put("name",name);
        map.put("position",position);
        return  contractService.findByPage(map);
    }

    @PostMapping
    public Result save(@RequestBody Contract contract){
        return contractService.save(contract);
    }
    @DeleteMapping
    public Result deleteById(@RequestParam("id") int id){
        int delete = contractService.delete(id);
        if (delete>0){
            return Result.success();
        }else {
            return Result.fail();
        }
    }
}
